package com.dongge.service;

import com.dongge.dao.CURDDaoBase;
import com.dongge.entity1.Comment;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2015/10/17.
 */
@Service
public class CommentService extends CURDDaoBase<Comment>{

    @Resource
    private ArticleService articleService;

    /**
     * 获取文章的评论列表(一级评论）
     * @param articleId
     * @return
     */
    public List<Comment> getArticleTopComments(Long articleId){
        if(articleId == null)
            return Collections.emptyList();
        String hsql =
                "from Comment p where p.article = :articleId and p.parent is null";
        return getSession().createQuery(hsql)
                .setLong("articleId",articleId)
                .list();
    }

}
